package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ0F implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x41:
                return handle0F41(cmd);
            case 0x44:
                return handle0F44(cmd);
            case 0x45:
                return handle0F45(cmd);
            case (byte) 0x92:
                return handle0F92(cmd);
            case 0x6e:
                return handle0F6E(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0F92(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:终端请求出租小汽车道路运输证");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(1,"出租小汽车道路运输证");
        list.put(2,"出租起床驾驶证");

        int type = cmd.readInt();

        builder.append("二维码类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");
        builder.append("从业资格证卡号："+cmd.readString(19));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0F45(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:终端请求下发交班及下班、充电状态LED屏显示信息");
        builder.append("\r\n");

        builder.append("准许证号："+cmd.readString(19));
        builder.append("\r\n");
        builder.append("车牌："+cmd.readString(9));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0F44(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:交班及下班、充电状态记录数据上传");
        builder.append("\r\n");
        builder.append("LED屏状态开始位置基本信息：");
        SZ_2021Utils.handle0200Base(cmd,builder);
        builder.append("LED屏状态结束位置基本信息：");
        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("准许证号："+cmd.readString(19));
        builder.append("\r\n");
        builder.append("车牌："+cmd.readString(9));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"双班司机交接班");
        list.put(1,"单班司机下班");
        list.put(2,"车辆充电");

        builder.append("LED状态:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");
        builder.append("LED显示内容："+cmd.readString(-1));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle0F41(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:终端请求下发司机信息指令");
        builder.append("\r\n");
        builder.append("从业资格证号："+cmd.readString(19));
        builder.append("\r\n");
        builder.append("车牌："+cmd.readString(9));
        builder.append("\r\n");
        builder.append("是否需要下发照片："+(cmd.readInt() == 0?"下发司机信息和照片":"下发司机信息不发照片"));
        builder.append("\r\n");
        
        return builder.toString();
    }

    private String handle0F6E(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:上报数据汇总");
        builder.append("\r\n");
        builder.append("统计日期："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("要上报的平台总数："+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("上报的平台1的地址："+cmd.readString(-1));
        builder.append("\r\n");
        builder.append("上报的平台1的端口："+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("平台1协议ID数量："+cmd.readInt(1));
        builder.append("\r\n");

        while (cmd.leftSize() > 2){
            builder.append("协议ID："+cmd.readInt(2));
            builder.append("\r\n");
            builder.append("协议条数："+cmd.readInt(4));
            builder.append("\r\n");
        }

        return builder.toString();
    }
}
